Imports System.IO

Partial Class thumbs
    Inherits System.Web.UI.UserControl
    Public mVerz As String
    Public mAnzahl As Long
    Property Verz() As String
        Get
            Return mVerz
        End Get
        Set(ByVal value As String)
            mVerz = value
            show_files()
        End Set
    End Property

    Property Anzahl() As Long
        Get
            Anzahl = mAnzahl
        End Get
        Set(ByVal value As Long)
            mAnzahl = value
            dlImages.RepeatColumns = mAnzahl
        End Set
    End Property

    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    End Sub

    Sub show_files()
        Dim strVerz As String = Nothing

        strVerz = Server.MapPath(Verz)
        'Dim files() As String = Directory.GetFiles(strVerz, "*.JPG")
        Dim files() As String = Directory.GetFiles(strVerz, "*.JPG")
        dlImages.DataSource = files
        dlImages.DataBind()
    End Sub

    Protected Sub dlImages_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
        Dim img As System.Web.UI.WebControls.ImageButton
        Dim imgstr As String = Nothing

        'make sure this is an item in the data list (not header etc.)
        If ((e.Item.ItemType = ListItemType.Item) Or _
         (e.Item.ItemType = ListItemType.AlternatingItem)) Then
            'get a reference to the image used for the bar in the row
            img = CType(e.Item.FindControl("imgThumbnail"), System.Web.UI.WebControls.ImageButton)
            'set the source to the page that generates the thumbnail image
            Dim d As String = e.Item.DataItem.ToString
            d = d.Substring(d.LastIndexOf("\") + 1)
            'img.ImageUrl = "admin/thumb.aspx?Bild=" & e.Item.DataItem.ToString
            imgstr = ""
            imgstr = Me.Verz & "/" & d
            imgstr = imgstr.Replace("\", "/")
            img.ImageUrl = imgstr
            img.CommandArgument = e.Item.DataItem.ToString

            'img.PostBackUrl = "diashow.aspx?Verz=" & Verz & "&Datei=" & d
        End If
    End Sub 'dlImages_ItemDataBound

    Sub Upload_Click(ByVal Sender As Object, ByVal e As EventArgs)
        Dim strFileName As String = MyFile.PostedFile.FileName
        Dim c As String = System.IO.Path.GetFileName(strFileName)
        c = Replace(c, " ", "_")
        If strFileName <> "" Then
            MyFile.PostedFile.SaveAs(MapPath(Request.QueryString("Verz")) & "\" & c)
        End If
        'show_files()
    End Sub
    Sub Bild_Click(ByVal Sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        'Response.Write(Sender.Imageurl.ToString)
        RaiseEvent OKClick(Sender.CommandArgument.ToString)
    End Sub
    Protected Sub imgKommentar_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        Response.Redirect("admin/kommentar.aspx?Datei=" & MapPath(Request.QueryString("Verz")) & "\kommentar.txt")
    End Sub
    Public Event OKClick(ByVal Pfad$)
End Class
